package com.yqd.lesson.actor.two

import scala.concurrent.duration._
import akka.actor
import akka.actor.{ActorRef, ActorSystem, PoisonPill}

import scala.util.Random

/*
  Actor 生命周期
 */
object Main extends App{

  //用户创建的顶级actor的监管者
  val system: ActorSystem = ActorSystem("helloAkka")

  //创建akka://helloAkka/user/printerActor
  val context: ActorRef = system.actorOf(Sender.props, "context")
  println("重启之前的Actor：" + context.toString())
  //此处会让Actor出错，默认是导致Actor重启
  context ! "hello"
  //此处会导致Acotr触发一个Timeout
  Thread.sleep(6000)
  println("重启之后的Actor：" + context.toString())
  context ! 2
  Thread.sleep(6000)
  //此处会导致Actor调用unhandled
  context ! true
  //管理者杀死监控Actor
  context ! PoisonPill
  system.terminate();
}
